extend ./layout/default

block main-content
  
  div.cheatsheet 
    h1 #{dataset.title}
    if user 
      if user.activated
        button.downloadbutton download
      else
        .error Sorry, you are not a certified user. 
        p 
          | click 
          a(href="/notify/unactived") here
          |  to be certified
    else 
      .error please login first
    
    div.cscontent !{dataset.content}
      
    if user && user.admin
       button.csbutton#editDataset Edit
       button.csbutton#deleteDataset Delete
    .error
  
  .breakLine
        
  div.comment
    h2 Comment
    .list
      each comment in dataset.comments
        .cscell(style="overflow: auto; margin-bottom: 10px;")
          svg(style="float: left;" width="40" height="40" data-jdenticon-hash="#{comment.author_hashId}")
          a(href="/user/#{comment.author}" style="margin-left:10px; text-decoration:none; color: #808080") #{comment.author}
          span :  #{comment.content}
  if user && user.activated  
    textarea(style="display:block;margin-top:10px;width:100%;" rows=5)
    button#addComment add your comment
    
  script.
    $('#addComment').click(function(){
      var content = $("textarea").val()
      $("textarea").val("")
      $.ajax({
        url: "/comment",
        data: {dsid: '#{dataset._id}',content: content},
        type: "post",
        success: function(data){
          if(data.status == "ok"){
            var div = document.createElement("div");
            div.className = "cscell";
            div.style.overflow = "auto";
            div.style.marginBottom = "10px";
            var a = document.createElement('a')
            a.href = "/user/#{user ? user.name : ''}"
            a.innerHTML = "#{user ? user.name : ''}"
            a.style = "margin-left:10px; text-decoration:none; color: #808080"
            div.appendChild(a)
            var span = document.createElement("span")
            span.innerHTML = ": " + content
            div.appendChild(span) 
            //- //- p.innerHTML = data.yourname+": "+content
            $(".list").append(div)
          }
        }      
      })
    })
  
    $('#editDataset').click(function(){
      location.href = "/edit/dataset/#{dataset._id}"
    })
    
    $('#deleteDataset').click(function(){
      $.ajax({
        url: '/dataset',
        data: {dsid: '#{dataset._id}'},
        type: 'DELETE',
        success: function(data){
          if(data.status == "ok"){
            location.href = "/"
          }
        }
      })
    })
    
    $('.downloadbutton').click(function(){
      var popupbg = document.createElement('div')
      popupbg.style.position = 'fixed'
      popupbg.style.width = '100%'
      popupbg.style.height = '100%'
      popupbg.style.top = 0
      popupbg.style.left = 0
      popupbg.style.background = 'rgba(50,50,50,0.5)'
      document.body.appendChild(popupbg)
      
      var popup = document.createElement('div')
      popup.style.position = 'absolute'
      popup.style.width = "60%"
      popup.style.height = "60%"
      popup.style.top = "20%"
      popup.style.left = "20%"
      popup.style.background = "white"
      popup.style.border = '1px solid #333'
      popup.style.borderRadius = '10px'
      popupbg.appendChild(popup)
      
      var close = document.createElement('div')
      close.style.position = 'absolute'
      close.style.top = '10px'
      close.style.right = '10px'
      close.style.width = '20px'
      close.style.height = '20px'
      close.style.lineHeight = '20p'
      close.style.border = '1px solid #111'
      close.style.borderRadius = '50%'
      close.innerHTML = "×"
      close.onclick = function(){
        popupbg.remove()
      }
      popup.appendChild(close)
      
      var msg = document.createElement('div')
      msg.style.position = 'absolute'
      msg.style.top = '40px'
      msg.style.width = "95%"
      msg.style.height = "80%"
      msg.style.marginLeft = '2.5%'
      
      msg.style.border = '1px solid #333'
      msg.style.borderRadius = '10px'
      msg.style.overflow = 'scroll'
      msg.style.padding = '5px'
      msg.style.wordSpacing = '0.3em';
      msg.style.lineHeight = '1.5em'
      //msg.innerHTML = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
      //msg.innerHTML += 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'  
      msg.innerHTML += '<h2>User Agreement</h2>'
      msg.innerHTML += '<br><br> 1.wico shall legally own the legal property rights of all data on this website'
      msg.innerHTML += '<br> 2.You shall warrant that it will not make use of the data and services provided by the site for unlawful activity.。'
      msg.innerHTML += '<br> 3.You shall not use the site data for any commercial use and profit unless explicitly authorized.'
      msg.innerHTML += '<br> 4.should clearly indicate the source of the data and the date downloaded from the site in any form of use or on the second development of the data and services provided by the site.'
      msg.innerHTML += '<br> 5.should note the data sources and extend thanks to the data providers in its text if it quote from the date and the data analysis results in the site in its paper or such as the publication of the article.'
      msg.innerHTML += '<br> 6.The data provided by the site are free, and Wico reserve the right of charge for customized measurement data'
      msg.innerHTML += '<br> 7.We shall warrant keeping secret all information of you and not to disclose it to any third party or authorize any third party to use it unless it is based on the need to provide you with an effective response.'
      msg.innerHTML += '<br> 8.When You are in any way to log on the site and directly or indirectly uses the site information, is seen as a voluntary acceptance of the constraints of this agreement.'
      msg.innerHTML += '<br> 9.Neither database site nor any of its content providers shall be liable for any indirect, incidental, special or consequential damages arising out of use of the site, inability to use the site or any content on the site.。'
      msg.innerHTML += '<br> 10.Wico will not be liable to you in any manner whatsoever for any consequences of any delay or interruption in the delivery or updating of the site or difficulties in Internet access equipment or hardware or software breaks down.'
      msg.innerHTML += '<br> 11.Wico will not be liable to any personal data leakage due to you telling others the personal password or sharing a registered account with others .'
      msg.innerHTML += '<br> 12.Wico will not be liable to any disclosure, lost, stolen or tampered of personal data due to hacker attacks, computer viruses invade or attack, temporary closure caused by government regulation and other effects of the network normal operation of force majeure.'
      msg.innerHTML += '<br> 13.Wico will not be liable to any disclosure of personal data legal disputes and consequences resulting from it due to other sites linked to the site.'
      msg.innerHTML += '<br> 14.Wico will announce in advance if it need to suspend service as a result of system maintenance or upgrade. The site will not be liable to any inconvenience or loss in the suspend service period caused by line fault or hardware failure outside our control.'
      msg.innerHTML += '<br> 15.If you violates the law as a result of violation of the provisions of this agreement, all the legal consequences and liabilities will be taken by yourself.'
      msg.innerHTML += '<br> 16.Wico will not guarantee for you to provide convenient and the accuracy and completeness of the set of external links. At the same time, for the external links to not by the site actual control of any web page content, Wico does not assume any responsibility.'
      msg.innerHTML += '<br> 17.The final interpretation of this Agreement shall be owned by Wico. All disputes arising from the execution of, or in connection with this Agreement shall be settled through friendly consultations between the Parties. If no settlement can be reached through consultation, the dispute shall be submitted to the court where Wico is located.'
      popup.appendChild(msg)  
      
      var ck = document.createElement('div')
      ck.style.position = 'absolute'
      ck.style.bottom = '10px'
      ck.style.left = '10px'
      popup.appendChild(ck)
      
      var checkBox = document.createElement('input')
      checkBox.type = 'checkbox'
      ck.appendChild(checkBox)
      
      var label = document.createElement('span')
      label.innerHTML = "I have read this User Agreement, and I totally agree all of it"
      ck.appendChild(label)
      
      var btn;
      
      checkBox.onchange = function(){
        if(checkBox.checked){
          btn = document.createElement('a')
          btn.innerHTML = "click to download"
          btn.style.border = '1px solid #333'
          btn.marginLeft = "40px"
          btn.href = "ftp://ftp1.wise.sh/" + '#{dataset.url}'
          console.log(btn.href)
          ck.appendChild(btn)
        }else{
          btn.remove()
        }
      }
    })
